<template>
	<view class="entire">
		<!-- 		<scroll-view :style="'height: ' + scrollHeight + 'px;'" scroll-y="true" :lower-threshold="lowerThreshold"
			@scrolltolower="loadMoreData"> -->
		<view>
			<head-list @refresh-page="refreshCurrentPage" :changing="2"></head-list>
		</view>

		<scroll-view scroll-x class="bg-Midnight-Blue nav" scroll-with-animation :scroll-left="scrollLeft">
			<view class="cu-item" :class="index==TabCur?'text-cyan curtext':'text-white'"
				v-for="(item,index) in classification" :key="index" @tap="tabSelect" :data-id="index">
				{{item.name}}
			</view>
		</scroll-view>

		<view class="chatIcon_operate_cate">
			<view v-for="(item, index) in dateType" :key="index"
				:class="item.active ? 'chatIcon_operate_cate_item active' : 'chatIcon_operate_cate_item'"
				@click="clickDate(index, item.id)">
				{{ item.name }}
			</view>

			<view class="block" style="width: 50%;margin-top: 12px;">
				<fui-button background="#0B3D6C" width="100%" height="32px" color="#ffffff" size="23" text="选择日期范围" bold
					@click="btnClick()"></fui-button>
				<fui-date-picker :show="datashow" :type="3" :range="range" :value="datavalue" :valueEnd="valueEnd"
					@change="change" @cancel="cancel">
				</fui-date-picker>
			</view>
		</view>

		<view class="title"> {{title}}
			<view class="title_bottom"></view>
		</view>

		<view class="square" :class="'screenshot_'+index" style="position: relative;"
			v-for="(item, index) in allArrayList" :key="index">
			<view v-if="item.recommended==1" style="position: absolute;right: 20rpx;top: 10rpx;">
				<image src="@/static/refined1.png" style="width: 70rpx;height: 70rpx"></image>
			</view>
			<view v-if="item.is_top==1" style="position: absolute;right: 110rpx;top: 10rpx;">
				<image src="@/static/topping1.png" style="width: 70rpx;height: 70rpx"></image>
			</view>

			<view class="flex p-xs margin-bottom-sm mb-sm">
				<view class="flex-quadruple padding-sm margin-xs radius" style="padding-right: 0 !important;">
					<view class='headimg'>
						<image style="width: 100%;height: 100%;border-radius: 100rpx;" :src="item.avatar"></image>
					</view>
				</view>
				<view class="flex-sub padding-sm margin-xs radius"
					style="width: 56% !important;padding-left: 0 !important;">
					<view style="font-size: 35rpx;color: white;">{{item.username}}</view>
					<view style="font-size: 25rpx;color: #b1c2d7;">{{item.create_time}}</view>
				</view>

				<view style="display: flex;padding: 25rpx 20rpx 0 0;" v-if="item.is_author == 1">
					<!-- <view style="font-size: 25rpx;color:#fff;padding-right: 20rpx;" @click="deletePost(item)">删除</view>
					<view style="font-size: 25rpx;color:#fff;" @click="updatePost(item)">修改</view> -->
					<view @click="showActionSheet(item)">
						<image src="../../static/dian.png" style="width: 30rpx;height: 30rpx;"></image>
					</view>
				</view>

			</view>
			<view class="flex p-xs margin-bottom-sm mb-sm" style="margin-top: -50rpx;">
				<view class="flex-sub padding-sm margin-xs radius rich-text-container" style="width: 98%;">
					<rich-text :class="{ 'textinfo': !item.isExpend }" selectable="true" class="rich-text"
						style="width: 98%;font-size: 30rpx;color: white;overflow: hidden; text-overflow: ellipsis;"
						:nodes="item.post_content.replace(/\n/g, '<br>')"></rich-text>
					<div
						style="width: 100%;text-align: center;margin: 5px;color: #e7d119;font-size: 10px;word-wrap: break-word;">
						<span v-if="!item.isExpend && calculateWordCount(item.post_content) > 150"
							style="cursor: pointer;font-size: 30rpx;font-weight: 600;" @click="expand(item)">展开</span>
						<span v-if="item.isExpend && calculateWordCount(item.post_content) > 150"
							style="cursor: pointer;font-size: 30rpx;font-weight: 600;"
							@click="expand_hide(item)">收起</span>
					</div>

				</view>
			</view>

			<view>
				<view v-for="(img,img_index) in item.file_img" :key="img_index"
					v-if="item.file_img && item.file_img.length > 0"
					style="display: inline-block;width: 30%;height: 180rpx;padding: 0 10rpx;">
					<image style="width: 100%;height: 100%;margin-left: 30rpx;" @click="tankuang(img,item.file_img)"
						:src="img" mode="aspectFill"></image>
				</view>
			</view>

			<view style="display: flex; justify-content: center; align-items: center;"
				v-for="(video,index) in item.file_video" :key="index">
				<video :src="video"></video>
			</view>

			<view v-for="(datafile,ind) in item.file_data" :key="ind">
				<view
					style="color:#26c3dd; padding:10rpx 0 10rpx 20rpx;overflow: hidden;word-wrap: break-word;word-break: break-all;"
					@click="downloadFiles(ind,datafile)">
					{{datafile.filename}}
				</view>
			</view>
			<view class="flex p-xs margin-bottom-sm mb-sm" style="margin-top: -10rpx;flex-grow: 1;overflow-y: auto;">
				<view style="width: 100%;display: flex;align-items: center;">
					<view class="flex-sub padding-sm margin-xs radius" style="padding-left: 10rpx;position: relative;">

						<textarea class="inputstyle_sty"
							:style="{ height: textareaHeight[item.id] ? textareaHeight[item.id] : '60rpx',paddingTop: paddingTop11 }"
							style="padding-right: 55px;text-align: left;height: 60rpx;padding-top: 4rpx;" v-model="commentText[item.id]"
							placeholder="欢迎评论" rows="1" @input="updateTextareaHeight($event,item.id)"></textarea>
						<image
							style="width: 50rpx;height:50rpx;position: absolute;bottom:24rpx;right: 40rpx;z-index:999;"
							@click="ChooseImage(item.id,1)" src="@/static/upimg.png"></image>
						<image
							style="width: 50rpx;height:50rpx;position: absolute;bottom:24rpx;right: 90rpx;z-index:999;"
							@click="showPopup(item.id)" src="@/static/emoji1.png"></image>
					</view>

					<fui-bottom-popup :show="show4" @close="closePopup()" maskBackground="rgba(0,0,0,0.1)">
						<view class="fui-custom__wrap">
							<chat-icon @changeText="getIcon($event)"></chat-icon>
						</view>
					</fui-bottom-popup>

					<view style="padding: 10rpx 20rpx 0 0;font-size: 40rpx;color: #fff;font-size: 30rpx;"
						@click="submit(item.id,item.channel_pid,item.channel_id)">
						发送
					</view>
				</view>

			</view>
			<view style="width: 100%;height: 200rpx;" v-if="imgList.length > 0 && img_id == item.id">
				<view style="display: inline-block;position: relative;" v-for="(img,index2) in imgList" :key="index2">
					<image style="width: 160rpx;height: 160rpx;float: left;padding-left: 20rpx;" :src="img"></image>
					<image style="width: 30rpx;height: 30rpx;position: absolute;top: -15rpx;right: -15rpx;"
						@click="delimg(index2)" src="@/static/close.png"></image>
				</view>
			</view>
			<view style="width:95%;margin:auto;height:5rpx;background-color:#6386b5;margin-top:-20rpx;"></view>
			<view class="flex p-xs margin-bottom-sm mb-sm" style="height: 70rpx;">
				<view class="flex-sub padding-sm margin-xs radius share-button"
					style="height: 60rpx;display: flex;align-items: center;">
					<button open-type="share" @click.stop="shareFun(item,index)" class="share_btn"
						style="background-color: #0d4283;border: none;outline: none;height: 40rpx;">
						<view class='cuIcon-post text-white'
							style="font-size: 30rpx;height: 35rpx;display: flex;align-items: center;justify-content: center;">
						</view>
					</button>
				</view>
				<view class="flex-sub padding-sm margin-xs radius"
					style="display: flex;align-items: center;justify-content: center;" @click="postinfo(item.id)">
					<view class='cuIcon-comment text-white' style="font-size: 30rpx;">{{item.comment_count}}</view>
				</view>
				<view class="flex-sub padding-sm margin-xs radius"
					style="display: flex;align-items: center;justify-content: center;">
					<view class='cuIcon-appreciatefill text-white' style="color: #F4C044;font-size: 40rpx;"
						@click="uncollect(item.id)" v-if="item.is_myfavorite == 1">{{item.post_favorites}}</view>
					<view class='cuIcon-appreciate text-white' style="font-size: 30rpx;" @click="collect(item.id)"
						v-else>
						{{item.post_favorites}}
					</view>
				</view>
			</view>
		</view>


		<!-- <view class="cu-modal" :class="modalName3=='menuModal3'?'show':''" @tap="hideModal3">
				<view class="cu-dialog" @tap.stop>
					<view style="padding: 20rpx 0 30rpx 30rpx;font-size: 40rpx;font-weight: 600;">
						修改评论</view>
					<view class="flex p-xs margin-bottom-sm mb-sm" style="">
						<view class="flex-quadruple padding-sm margin-xs radius" style="padding-right: 0;">
							<view class='headimg1'>
								<image style="width: 100%;height: 100%;border-radius: 100rpx;" :src="userinfo.avatar">
								</image>
							</view>
						</view>

						<view class="flex-sub padding-sm margin-xs radius" style="padding-left: 0;position: relative;">
							<input class="inputstyle" v-model="text4" placeholder=""></input>
							<image
								style="width: 50rpx;height:50rpx;position: absolute;top:30rpx;right: 30rpx;z-index:999;"
								@click="update_ChooseImage()" src="@/static/upimg.png"></image>
						</view>

						<view style="padding: 20rpx 20rpx 0 0;font-size: 40rpx;color: #000000;margin-top: 18rpx;"
							@click="comment_update()">
							发送
						</view>
					</view>
					<view style="width: 100%;height: 200rpx;" v-if="imgListsss.length > 0">
						<view style="display: inline-block;position: relative;" v-for="(img,index4) in imgListsss"
							:key="index4">
							<image style="width: 160rpx;height: 160rpx;float: left;padding-left: 20rpx;" :src="img">
							</image>
							<image style="width: 30rpx;height: 30rpx;position: absolute;top: -15rpx;right: -15rpx;"
								@click="delimg_update(index4)" src="@/static/close.png"></image>
						</view>
					</view>
				</view>
			</view> -->

		<view style="width: 100%;height: 70rpx;text-align: center;color:#fff;" v-if="pagetype == 2">暂无更多数据！</view>
		<fui-loading :isFixed="true" srcCol="/static/loading_white.png" text="正在加载..." v-if="loading"></fui-loading>
		<view style="width: 100%;height: 130rpx;"></view>

		<fui-actionsheet :show="show_dian" :tips="tips" :itemList="itemList" :isCancel="isCancel" :theme="theme"
			@click="itemClick" @cancel="cancel_dian" :maskClosable='true'></fui-actionsheet>
		<!-- </scroll-view> -->
	</view>
</template>

<script>
	import {
		setTabCurrent
	} from "@/common/swiperTools.js"
	import chatIcon from '@/components/chatIcon.vue'
	import user from '@/api/user.js';
	import forum from '@/api/forum.js';
	import {
		img_upload
	} from '@/common/config'
	import HeadList from '@/components/head.vue';
	import saveImage from '@/common/saveImage.js'
	export default {
		props: ['userinfo', 'minute', 'classification', 'default_array', 'fids', 'fid_array'],
		components: {
			HeadList,
			chatIcon
		},
		data() {
			return {
				postContents: [],
				loading: false,
				show4: false,
				HDComTextareaContent: '', //textarea框的值
				forum_comment: [],
				forum_id: [],
				comment_page: 1,
				commentText: {},
				token: '',
				TabCur: 0,
				scrollLeft: 0,
				title: '债市广场',
				localArray: [],
				allArray: [],
				updateList: [],
				type: 1,
				scrollHeight: 0,
				lowerThreshold: 10,
				isReachedBottom: false,
				page: 2,
				limits: 1,
				pagetype: 1,
				modalName: null,
				modalName1: null,
				modalName2: null,
				modalName3: null,
				swiperList: [],
				herald: [],
				fid: 0,
				fid_type: 'plate',

				dotStyle: false,
				text2: '',
				text3: '',
				text4: '',
				aid: 0,
				pinglun_id: 0,
				//一级评论
				imgList: [],
				imgdata: [],
				file_img: [],
				file_imgs: [],
				img_id: '',
				//二级评论
				imgLists: [],
				imgdatas: [],
				file_imgs: [],
				file_imgss: [],
				img_ids: '',
				//三级评论
				imgListss: [],
				imgdatass: [],
				file_imgss: [],
				file_imgsss: [],
				img_idss: '',
				//修改评论
				imgListsss: [],
				imgdatasss: [],
				file_imgsss: [],
				file_imgssss: [],
				img_idsss: '',
				//上传图片类型 1一级2二级3三级
				img_type: 1,

				//今日、七日、月、年
				dateType: [{
						name: '全部',
						id: 0,
						active: false
					},{
						name: '今日',
						id: 1,
						active: false
					},
					{
						name: '七日',
						id: 2,
						active: false
					},
					{
						name: '月',
						id: 3,
						active: false
					},
					{
						name: '年',
						id: 4,
						active: false
					}
				],
				dateTypes: 'all',
				//日期
				result: '',
				range: true,
				//默认值
				datavalue: '2024-06-15',
				valueEnd: '',
				datashow: false,
				start_time: '',
				end_time: '',
				emoji_text: '',
				show_dian: false,
				tips: '',
				itemList: [],
				isCancel: true,
				theme: 'light',
				array_item: [],
				is_textinfo: true,
				textareaHeight: {},
				url: '',
				url_iamge: '',
				url_text: '',
				paddingTop11: '8rpx'
			}
		},
		computed: {
			allArrayList() {
				let resultArr = []
				if (this.type == 1) {
					if (this.default_array) {
						resultArr = Object.keys(this.default_array).length ? this.default_array.plateList : []
					} else {
						resultArr = []
					}
				} else {
					if (this.allArray) {
						resultArr = Object.keys(this.allArray).length ? this.allArray.plateList : []
					} else {
						resultArr = []
					}
				}
				resultArr.forEach(el => {
					if (el.isExpend === undefined) {
						this.$set(el, 'isExpend', false)
					}
				})
				return resultArr
			}
		},
		watch: {
			fids(newValue, oldValue) {
				if (newValue !== oldValue) {
					this.fid = newValue;
					console.log(this.fid, 888)
				}
			},
		},
		created() {
			const token = uni.getStorageSync('token');
			this.token = token
			this.TowerSwiper('swiperList');
			this.fid = uni.getStorageSync('fid') ? uni.getStorageSync('fid') : this.fids;
			this.fid = this.fid != 0 ? this.fid : 18;
			uni.setStorageSync('fid', this.fid);
			let TabCur = uni.getStorageSync('TabCur');
			if (TabCur != '' && TabCur != 0) {
				this.TabCur = TabCur
			} else {
				this.TabCur = 0
			}
			// this.infoList(this.fid)
		},
		mounted() {
			uni.getSystemInfo({
				success: (res) => {
					this.scrollHeight = res.windowHeight;
				},
			});
			let khdtype = uni.getSystemInfoSync().platform
			if (khdtype == 'ios') {
				this.paddingTop11 = '0'
			} else{
				this.paddingTop11 = '8rpx'
			}
		},
		onShareAppMessage() {
			return {
				title: this.url_text,
				path: this.url,
				imageUrl: this.url_iamge
			}
		},
		methods: {

			updateTextareaHeight(event, id) {
				const value = event.target.value;
				if (value !== undefined) {
					const lines = value.split('\n').length;
					const liness = Math.ceil(value.length / 8);
					const num = lines + liness
					this.textareaHeight[id] = `${num * 20 * 2}rpx`;
				}
			},
			calculateWordCount(item) {
				const plainText = item.replace(/<[^>]*>/g, '');
				const contentForCount = plainText.trim();
				return contentForCount.length;
			},
			expand(item) {
				item.isExpend = true
				this.$forceUpdate()
			},
			expand_hide(item) {
				item.isExpend = false
				console.log(item)
				this.$forceUpdate()
			},
			showActionSheet(item) {
				this.array_item = item
				this.tips = '';
				this.isCancel = true;
				this.theme = 'light';
				this.itemList = ['删除', '修改']
				setTimeout(() => {
					this.show_dian = true
				}, 50)
			},
			itemClick(e) {
				if (e.index == 0) {
					this.deletePost(this.array_item)
				} else if (e.index == 1) {
					this.updatePost(this.array_item)
				} else {
					this.cancel_dian()
				}
			},
			cancel_dian() {
				this.show_dian = false
			},
			drop_down() {
				this.TabCur = uni.getStorageSync('TabCur');
				this.infoList(uni.getStorageSync('fid'))
			},
			getIcon(e) {
				console.log(e)
				if (this.commentText[this.emoji_text] == undefined) {
					this.commentText[this.emoji_text] = e
				} else {
					this.commentText[this.emoji_text] += e
				}
				this.closePopup()
			},
			showPopup(item) {
				this.emoji_text = item
				this.show4 = true
			},
			closePopup() {
				this.show4 = false
			},
			onShow() {
				this.infoList(this.fid)
			},
			refreshCurrentPage() {
				this.infoList(uni.getStorageSync('fid'))
			},
			//图片预览
			tankuang(url, arr) {
				uni.previewImage({
					current: url,
					urls: arr,
					loop: true,
				});
			},
			//图片上传弹框
			ChooseImage(id, type) {
				uni.chooseImage({
					count: 3, //默认9 
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							this.uploadFile(res.tempFilePaths[i], id, type);
						}
					}
				});
			},
			//图片上传
			uploadFile(filePath, id, type) {
				uni.uploadFile({
					url: img_upload,
					filePath: filePath,
					name: 'file',
					formData: {
						'user': 'test',
						'token': this.token
					},
					success: (uploadRes) => {
						const responseObject = JSON.parse(uploadRes.data);
						if (responseObject.code == 403) {
							uni.showToast({
								title: responseObject.msg,
								icon: 'error'
							})
						} else {
							this.img_type = type
							if (type == 1) {
								if (this.imgList.length < 3) {
									console.log(responseObject)
									this.imgdata.push(responseObject.data.fullurl)
									this.imgList = this.imgdata
									this.file_imgs.push(responseObject.data.url)
									this.file_img = this.file_imgs
									this.img_id = id
								} else {
									uni.showToast({
										title: '最多上传三张照片',
										icon: 'none'
									})
								}
							} else if (type == 2) {
								if (this.imgLists.length < 3) {
									console.log(responseObject)
									this.imgdatas.push(responseObject.data.fullurl)
									this.imgLists = this.imgdatas
									this.file_imgss.push(responseObject.data.url)
									this.file_imgs = this.file_imgss
									this.img_ids = id
								} else {
									uni.showToast({
										title: '最多上传三张照片',
										icon: 'none'
									})
								}
							} else {
								if (this.imgListss.length < 3) {
									console.log(responseObject)
									this.imgdatass.push(responseObject.data.fullurl)
									this.imgListss = this.imgdatass
									this.file_imgsss.push(responseObject.data.url)
									this.file_imgss = this.file_imgss
									this.img_idss = id
								} else {
									uni.showToast({
										title: '最多上传三张照片',
										icon: 'none'
									})
								}
							}
						}
					},
					fail: (error) => {
						console.log(error);
					}
				});
			},
			//修改评论图传上传弹窗
			update_ChooseImage() {
				uni.chooseImage({
					count: 3, //默认9 
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							this.uploadFile1(res.tempFilePaths[i]);
						}
					}
				});
			},
			//修改评论图片上传
			uploadFile1(filePath) {
				uni.uploadFile({
					url: img_upload,
					filePath: filePath,
					name: 'file',
					formData: {
						'user': 'test',
						'token': this.token
					},
					success: (uploadRes) => {
						const responseObject = JSON.parse(uploadRes.data);
						if (responseObject.code == 403) {
							uni.showToast({
								title: responseObject.msg,
								icon: 'error'
							})
						} else {
							if (this.imgList.length < 3) {
								console.log(responseObject)
								this.imgListsss.push(responseObject.data.fullurl)
							} else {
								uni.showToast({
									title: '最多上传三张照片',
									icon: 'none'
								})
							}
						}
					},
					fail: (error) => {
						console.log(error);
					}
				});
			},
			//删除修改时上传的图片
			delimg_update(e) {
				this.imgListsss.splice(e, 1);
			},
			//删除评论时上传的图片
			delimg(e) {
				if (this.img_type == 1) {
					this.file_img.splice(e, 1);
					this.imgList.splice(e, 1);
				} else if (this.img_type == 2) {
					this.file_imgs.splice(e, 1);
					this.imgLists.splice(e, 1);
				} else {
					this.file_imgss.splice(e, 1);
					this.imgListss.splice(e, 1);
				}
			},
			loadMoreData() {
				if (!this.isReachedBottom) {
					this.loadData();
					this.isReachedBottom = true;
					this.refresh_now();
				}
			},
			loadData() {
				setTimeout(() => {
					this.isReachedBottom = false; // 重置状态，以便下次触发加载更多
				}, 1000);
			},
			setTabCurrent,
			tabSelect(e) {
				this.loading = true
				this.page = 1
				this.TabCur = e?.currentTarget?.dataset?.id || 0;
				this.fid = this.classification[this.TabCur].id
				this.fid_type = 'plate'
				uni.setStorageSync('TabCur', this.TabCur);
				uni.setStorageSync('fid', this.fid);
				uni.setStorageSync('fid_type', this.fid_type);
				forum.forumindex({
					token: this.token,
					category_id: this.classification[this.TabCur].id,
					category_type: 'plate',
					type: this.dateTypes,
					Page: 1,
					limit: 5,
					start_time: this.start_time,
					end_time: this.end_time,
				}).then(res => {
					this.loading = false
					if (res.msg == "尚未开通会员") {
						this.localArray = []
						this.allArray = []
						this.type = 2
						uni.showModal({
							title: '会员',
							content: '开通会员',
							cancelText: '取消',
							confirmText: '确定',
							success: res => {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/membership/membership'
									})
								} else {
									uni.navigateTo({
										url: '/pages/index/index'
									})
								}
							}
						})
					} else {
						this.localArray = res.data
						this.allArray = res.data
						this.type = 2
					}
				})

				this.scrollLeft = ((e?.currentTarget?.dataset?.id || e) - 1) * 60
			},
			myinfo() {
				uni.navigateTo({
					url: '/pages/index/myinfo'
				});
			},
			//下拉加载
			refresh_now() {
				this.loading = true
				forum.forumindex({
					token: this.token,
					category_id: this.fid,
					category_type: 'plate',
					type: this.dateTypes,
					page: this.page,
					limit: 5,
					start_time: this.start_time,
					end_time: this.end_time,
				}).then(res => {
					this.loading = false
					let data = res.data
					this.limits = Math.ceil(res.data['total'] / 5);
					if (this.type !== 2) {
						this.allArray = this.default_array
					}
					for (let i = 0; i < data['plateList'].length; i++) {
						this.allArray['plateList'].push(data['plateList'][i])
					}
					this.localArray = this.allArray
					this.type = 2
				})
				if (this.page - 1 > this.limits) {
					this.pagetype = 2
				}
				this.page++
			},
			downloadFiles(index, datafile) {
				const url = datafile.url; // 替换为实际文件的URL
				const fileName = datafile.filename; // 替换为实际文件的名称
				const res = uni.downloadFile({
					url: url,
					success: (downloadResult) => { // 使用箭头函数
						if (downloadResult.statusCode === 200) {
							const tempFilePath = downloadResult.tempFilePath
							console.log(tempFilePath, 888)
							uni.showToast({
								title: '下载成功',
								icon: 'success'
							})
							this.openTempFile(tempFilePath) // 此处的this仍然指向downloadFiles函数
						} else {
							console.error('文件下载失败')
						}
					},
					fail: (error) => { // 使用箭头函数
						console.error('文件下载失败', error)
					}
				})
				res.onProgressUpdate((progress) => {
					console.log('下载进度：' + progress.progress)
				})
			},
			openTempFile(url) {
				wx.openDocument({
					filePath: url,
					success: (res) => { // 使用箭头函数
						console.log('临时文件打开成功')
					},
					fail: (error) => { // 使用箭头函数
						console.error('打开临时文件失败', error)
					}
				})
			},
			deletePost(item) {
				uni.showModal({
					title: '',
					content: '确定要删除吗？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							forum.delPost({
								category_type: item.category_type,
								id: item.id
							}).then(res => {
								if (res.code === 1) {
									uni.showToast({
										title: '删除成功',
										icon: 'success'
									})
									this.cancel_dian()
									this.infoList(this.fid)
								}
							})
						}
					}
				})
			},
			updatePost(item) {
				console.log(item)
				uni.redirectTo({
					url: '/pages/index/updatePost'
				});
				uni.setStorageSync('arrayList', item);
			},
			infoList(id) {
				this.loading = true
				forum.forumindex({
					token: this.token,
					category_id: id,
					category_type: 'plate',
					type: this.dateTypes,
					Page: 1,
					limit: 5,
					start_time: this.start_time,
					end_time: this.end_time,
				}).then(res => {
					this.loading = false
					if (res.msg == "尚未开通会员") {
						this.localArray = []
						this.allArray = []
						this.type = 2
						uni.showModal({
							title: '会员',
							content: '开通会员',
							cancelText: '取消',
							confirmText: '确定',
							success: res => {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/membership/membership'
									})
								}
							}
						})
					} else {
						this.allArray = res.data
						this.type = 2
					}
				})
			},
			deleteComment(id) {
				forum.delComment({
					id: id
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '删除成功',
							icon: 'success'
						})
						this.infoList(this.fid)
					}
				})
			},
			collect(id) {
				forum.addFavorite({
					token: this.token,
					table_name: 'plate_post',
					object_id: id,
				}).then(res => {
					if (res.code == 1) {
						if (this.type == 2) {
							for (let i = 0; i < this.allArray['plateList'].length; i++) {
								if (this.allArray['plateList'][i]['id'] == id) {
									if (this.allArray['plateList'][i]['is_myfavorite'] != 1) {
										this.allArray['plateList'][i]['is_myfavorite'] = 1
										this.allArray['plateList'][i]['post_favorites'] = res.data.post_favorites
									}
								}
							}
						} else {
							forum.forumindex({
								token: this.token,
								category_id: this.fid,
								category_type: 'plate',
								type: 4,
								page: 1,
								limit: 5,
							}).then(res => {
								this.allArray = res.data
								this.type = 3
							})
						}
					}
				})
			},
			uncollect(id) {
				forum.delFavorite({
					token: this.token,
					table_name: 'plate_post',
					object_id: id,
				}).then(res => {
					if (res.code == 1) {
						if (this.type == 2) {
							for (let i = 0; i < this.localArray['plateList'].length; i++) {
								if (this.localArray['plateList'][i]['id'] == id) {
									if (this.localArray['plateList'][i]['is_myfavorite'] != 0) {
										this.localArray['plateList'][i]['is_myfavorite'] = 0
										this.allArray['plateList'][i]['is_myfavorite'] = 0
										this.localArray['plateList'][i]['post_favorites'] = res.data.post_favorites
										this.allArray['plateList'][i]['post_favorites'] = res.data.post_favorites
									}
								}
							}
						} else {
							forum.forumindex({
								token: this.token,
								category_id: this.fid,
								category_type: 'plate',
								type: 4,
								page: 1,
								limit: 5,
							}).then(res => {
								let data = res.data
								const regex = new RegExp('img', 'gi')
								for (var i = 0; i < res.data['plateList'].length; i++) {
									data['plateList'][i].post_content = res.data['plateList'][i]
										.post_content.replaceAll(new RegExp('style="[^"]*"', 'gi'), '')
									data['plateList'][i].post_content = res.data['plateList'][i]
										.post_content.replace(regex,
											`img style="max-width:100%;"`) // 加上自己所需要的样式
								}
								this.allArray = data
								this.type = 3
							})
						}
					}
				})
			},
			removeHtmlTags(str) {
				return str.replace(/<[^>]+>/g, '');
			},
			getimage() {
				forum.getRandomShareCoverImage().then(res => {
					if (res.code == 1) {
						this.url_iamges = res.data.cover_image_url
					}
				})
			},
			shareFun(item, index) {
				this.url = '/pages/bondmarket/postinfo?id=' + item.id + '&fid=' + this.fid;
				if (item.post_content !== '') {
					this.url_text = this.removeHtmlTags(item.post_content);
				} else {
					this.url_text = '';
				}
				if (item.file_img.length !== 0) {
					this.url_iamge = item.file_img[0];
				} else {
					this.url_iamge = '';
				}

				uni.setStorageSync('url_text', this.url_text);
				uni.setStorageSync('img_url', this.url_iamge);
				uni.setStorageSync('url', this.url);
			},
			//帖子详情
			postinfo(id) {
				uni.navigateTo({
					url: '/pages/bondmarket/postinfo?id=' + id + '&fid=' + this.fid
				})
			},
			//发送一级评论 
			submit(wid, pid, id) {
				let text = this.commentText[wid] || '';
				let texts = this.commentText[wid] || '';
				if (this.file_img && this.file_img.length > 0) {
					for (let i = 0; i < this.file_img.length; i++) {
						text += `![Image Description](${this.file_img[i]})`
					}
				}
				forum.addComment({
					token: this.token,
					type: 'bbs',
					aid: wid,
					content: text,
					con: texts,
					image: this.imgList,
					pid: 0,
					top_pid: 0,
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '发布成功',
							icon: 'success'
						})
						this.imgList = []
						this.commentText[wid] = ''
						this.textareaHeight[wid] = `${1 * 15}px`;
						this.infoList(this.fid)
					}
				})
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
				forum.get_management({
					token: this.token,
				}).then(res => {
					if (res.code == 1) {
						this.swiperList = res.data
					}
				})
				forum.getLiveForeshow().then(res => {
					if (res.code == 1) {
						this.herald = res.data
					}
				})
			},
			showModal1(aid, id) {
				this.modalName1 = 'menuModal1'
				this.aid = aid
				this.pinglun_id = id
			},
			showModal2(aid, id) {
				this.modalName2 = 'menuModal2'
				this.aid = aid
				this.pinglun_id = id
				console.log(this.aid, this.pinglun_id, 555555)
			},
			showModal3(aid, id, item) {
				this.modalName3 = 'menuModal3'
				this.aid = aid
				this.pinglun_id = id
				this.updateList = item
				this.text4 = item.content_text
				this.imgListsss = item.content_files_img
				console.log(this.aid, this.pinglun_id, 555555)
			},
			hideModal(e) {
				this.modalName = null
			},
			hideModal1(e) {
				this.modalName1 = null
			},
			hideModal2(e) {
				this.modalName2 = null
			},
			hideModal3(e) {
				this.modalName3 = null
			},
			DotStyle(e) {
				this.dotStyle = e.detail.value
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			TowerSwiper(name) {
				let list = this[name];
				for (let i = 0; i < list.length; i++) {
					list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
					list[i].mLeft = i - parseInt(list.length / 2)
				}
				this.swiperList = list
			},

			// towerSwiper触摸开始
			TowerStart(e) {
				this.towerStart = e.touches[0].pageX
			},

			// towerSwiper计算方向
			TowerMove(e) {
				this.direction = e.touches[0].pageX - this.towerStart > 0 ? 'right' : 'left'
			},

			// towerSwiper计算滚动
			TowerEnd(e) {
				let direction = this.direction;
				let list = this.swiperList;
				if (direction == 'right') {
					let mLeft = list[0].mLeft;
					let zIndex = list[0].zIndex;
					for (let i = 1; i < this.swiperList.length; i++) {
						this.swiperList[i - 1].mLeft = this.swiperList[i].mLeft
						this.swiperList[i - 1].zIndex = this.swiperList[i].zIndex
					}
					this.swiperList[list.length - 1].mLeft = mLeft;
					this.swiperList[list.length - 1].zIndex = zIndex;
				} else {
					let mLeft = list[list.length - 1].mLeft;
					let zIndex = list[list.length - 1].zIndex;
					for (let i = this.swiperList.length - 1; i > 0; i--) {
						this.swiperList[i].mLeft = this.swiperList[i - 1].mLeft
						this.swiperList[i].zIndex = this.swiperList[i - 1].zIndex
					}
					this.swiperList[0].mLeft = mLeft;
					this.swiperList[0].zIndex = zIndex;
				}
				this.direction = ""
				this.swiperList = this.swiperList
			},
			//跳转
			broadcast(type, id) {
				uni.setStorageSync('livetype', type);
				uni.setStorageSync('liveid', id);
				uni.navigateTo({
					url: '/pages/index/livbroadcast'
				});
			},
			//查看评论
			see_more(id) {
				if (id != this.forum_id) {
					this.comment_page = 1
					this.forum_comment = []
				}
				forum.AlbumComment({
					token: this.token,
					aid: id,
					type: 'bbs',
					page: this.comment_page,
					limit: 5,
				}).then(res => {
					console.log(this.forum_comment)
					if (this.forum_comment.length == 0) {
						for (var i = 0; i < res.data['list'].length; i++) {
							if (res.data['list'][i]['content_files'] != '') {
								const imageUrlArray = res.data['list'][i]['content_files'].split(',');
								res.data['list'][i]['content_files_img'] = imageUrlArray
							} else {
								res.data['list'][i]['content_files_img'] = []
							}
							if (res.data['list'][i]['children'] != []) {
								for (var j = 0; j < res.data['list'][i]['children'].length; j++) {
									if (res.data['list'][i]['children']['content_files'] != '') {
										const imageUrlArrays = res.data['list'][i]['children'][j]['content_files']
											.split(',');
										res.data['list'][i]['children'][j]['content_files_img'] = imageUrlArrays
									} else {
										res.data['list'][i]['children'][j]['content_files_img'] = []
									}
								}
							}
						}
						this.forum_comment = res.data
					} else {
						for (let i = 0; i < res.data['list'].length; i++) {
							if (res.data['list'][i]['content_files'] != '') {
								const imageUrlArray = res.data['list'][i]['content_files'].split(',');
								res.data['list'][i]['content_files_img'] = imageUrlArray
							} else {
								res.data['list'][i]['content_files_img'] = []
							}
							if (res.data['list'][i]['children'] != []) {
								for (var j = 0; j < res.data['list'][i]['children'].length; j++) {
									if (res.data['list'][i]['children']['content_files'] != '') {
										const imageUrlArrayss = res.data['list'][i]['children'][j]['content_files']
											.split(',');
										res.data['list'][i]['children'][j]['content_files_img'] = imageUrlArrayss
									} else {
										res.data['list'][i]['children'][j]['content_files_img'] = []
									}
								}
							}
							this.forum_comment['list'].push(res.data['list'][i])
						}
					}

					console.log(this.forum_comment, 666)

					this.forum_id = id
					if (res.data.total == 0) {
						this.forum_comment = []
						uni.showToast({
							title: '暂无评论',
							icon: 'none'
						})
					}
				});
				this.comment_page += 1
			},
			//发送二级评论
			comment_first(aid, id) {
				let text = this.text2;
				let texts = this.text2;
				if (this.file_imgs && this.file_imgs.length > 0) {
					for (let i = 0; i < this.file_imgs.length; i++) {
						text += `![Image Description](${this.file_imgs[i]})`
					}
				}
				forum.addComment({
					token: this.token,
					type: 'bbs',
					aid: aid,
					content: text,
					con: texts,
					image: this.imgLists,
					pid: id,
					top_pid: aid,
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '发布成功',
							icon: 'success'
						})
					}
				})
				this.text2 = ''
				this.modalName1 = null
			},
			//发送三级评论
			comment_second(aid, id) {
				let text = this.text3;
				let texts = this.text3;
				if (this.file_imgss && this.file_imgss.length > 0) {
					for (let i = 0; i < this.file_imgss.length; i++) {
						text += `![Image Description](${this.file_imgss[i]})`
					}
				}
				forum.addComment({
					token: this.token,
					type: 'bbs',
					aid: aid,
					content: text,
					con: texts,
					image: this.imgListss,
					pid: id,
					top_pid: aid,
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '发布成功',
							icon: 'success'
						})
					}
				})
			},
			//修改评论
			comment_update() {
				let text = this.text4;
				let texts = this.text4;
				if (this.imgListsss && this.imgListsss.length > 0) {
					for (let i = 0; i < this.imgListsss.length; i++) {
						text += `![Image Description](${this.imgListsss[i]})`
					}
				}
				forum.updateComment({
					token: this.token,
					id: this.updateList.id,
					content: text,
					con: texts,
					image: this.imgListsss
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '修改成功',
							icon: 'success'
						})
					}
				})
			},
			//选择日期
			clickDate(i, id) {
				if(id == 0){
					this.dateTypes = 'all'
				}else{
					this.dateTypes = id
				}
				this.dateType.forEach((item, index) => {
					item.active = index === i
				})
				this.start_time = ''
				this.end_time = ''
				this.infoList(this.fid)
			},
			//日期选择器
			btnClick() {
				this.datashow = false
				//默认值，区间选择时起始值使用属性：value，结束值使用属性：valueEnd
				setTimeout(() => {
					this.datashow = true
				}, 80)
			},
			change(e) {
				this.datashow = false
				this.start_time = e.startDate.result
				this.end_time = e.endDate.result
				this.dateTypes = 'all'
				this.infoList(this.fid)
			},
			cancel() {
				this.datashow = false
			}
		}
	}
</script>

<style scoped>
	.inputstyle_sty {
		/* height: 70rpx; */
		border-radius: 15rpx;
		border: 3rpx white solid;
		background-color: white;
		padding-left: 30rpx;
		width: 97%;
		margin-top: 8px;
		font-size: 30rpx;
		overflow-y: auto;
		min-height: 60rpx;
		/* 		resize: none; */
		box-sizing: border-box;
		height: 25px;
		overflow: hidden;
		display: flex;
		align-items: flex-start;

	}

	.chatIcon_operate_cate {
		flex: 1;
		margin-left: 30rpx;
		display: flex;
		align-items: center;
		width: 100%;
	}

	.chatIcon_operate_cate_item {
		margin-top: 20rpx;
		width: 36px;
		height: 30px;
		line-height: 23px;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #0B3D6C;
		border-radius: 3px;
		font-size: 12px;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		margin-right: 9px;
		cursor: pointer;
	}

	.active {
		background: linear-gradient(0deg, #085EAF, #2791F4) !important;
	}

	.cu-modal {
		background: rgba(0, 0, 0, 0.1) !important;
	}

	.inputstyle {
		height: 70rpx;
		border-radius: 100rpx;
		border: 3rpx white solid;
		background-color: white;
		padding-left: 30rpx;
		flex-grow: 1;
		overflow-y: auto;
	}

	.headimg {
		width: 70rpx;
		height: 70rpx;
		border: 2rpx white solid;
		border-radius: 100rpx;
		background-size: cover;
		background-repeat: no-repeat;
		background-position: center;
	}

	.headimg1 {
		width: 60rpx;
		height: 60rpx;
		border: 2rpx white solid;
		border-radius: 100rpx;
		background-size: cover;
		background-repeat: no-repeat;
		background-position: center;
	}

	.title {
		width: 300rpx;
		height: 60rpx;
		font-size: 40rpx;
		font-weight: bold;
		text-align: left;
		padding-left: 10rpx;
		line-height: 50rpx;
		color: white;
		border-left: 15rpx #1eebe6 solid;
		margin: 50rpx 0 0 50rpx;
		z-index: 9999;
	}

	.title_bottom {
		width: 130rpx;
		height: 20rpx;
		border-radius: 50rpx;
		background-image: linear-gradient(to right, #1794a4, #157088, #123962);
		margin-top: -10rpx;
		margin-left: 10rpx;
		z-index: 9998;
	}

	.square {
		width: 90%;
		margin: 20rpx auto;
		background-color: #0d4283;
		border-radius: 15rpx;
	}

	.entire {
		width: 100vw;
		overflow: hidden;
		/* height: 100vh; */
		background-color: #112858;
	}

	.text {
		color: white;
		margin-left: 30rpx;
	}

	.bgwhite {
		background-color: #112858;
	}

	.curtext {
		text-align: center;
		border-radius: 100rpx;
		border: 4rpx cyan solid;
		background-image: linear-gradient(to right, #0b7284, #0e5070, #0b7284);
	}

	.introduce {
		width: 95%;
		border-radius: 12rpx;
		margin: 10rpx auto 20rpx;
	}

	.introduce_first {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.introduce_second {
		width: 95%;
		margin: auto;
		padding-bottom: 15rpx;
		padding-left: 20rpx;
	}

	.introduce_video {
		width: 98%;
		height: 100rpx;
		background-color: #1C416D;
		margin: 10rpx auto 0;
		border-radius: 16rpx;
		color: #fff;
		padding-left: 20rpx;
	}

	.introduce_video_text {
		text-align: center;
		line-height: 100rpx;
		color: #fff;
		padding-left: 10rpx;
	}

	.rich-text-container {
		width: 98%;
		font-size: 36rpx;
		color: white;
		overflow: hidden;
		word-wrap: break-word;
		word-break: break-all;
	}

	.rich-text-container::selection {
		background-color: #007bff;
		/* 设置选中文本的背景色 */
		color: white;
		/* 设置选中文本的文字颜色 */
	}

	.rich-text {
		user-select: text;
		/* 允许文本选择 */
	}

	.entire .nav .cu-item {
		height: 60rpx !important;
		line-height: 60rpx !important;
	}

	.share-button button {
		border: 0 !important;
		outline: none !important;
	}

	.fui-custom__wrap {
		width: 100%;
		height: 520rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.fui-page__bd {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.fui-actionsheet__show {
		margin-bottom: 120rpx;
	}

	.share_btn::after {
		border: initial;
	}

	.textinfo {
		display: -webkit-box;
		-webkit-line-clamp: 10;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>